import transformUrl from "utils/transfomUrl"
import transformData from "utils/transformData"
export default function(axiosIns,config){
    let obj = {};
    const {api={}} = config;
    for(let key in api){
        let {url="",method="get",configData={}} = api[key];
        obj[key] = async function(options={}){
            let body = "";
            const data = transformData(configData,options);
            const lastUrl = transformUrl(url,method,options);
            switch (method.toLowerCase()){
                case "get":
                case "delete":
                    body = await axiosIns({
                    url:lastUrl,
                    method,
                });
                break;
                case "put":
                case "post":
                case "patch":
                    body = await axiosIns({
                        url:lastUrl,
                        method,
                        data
                    })
            }
            return body;
        }
    }
    return obj
}